package com.gs.study.web;

import java.time.LocalDateTime;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gs.study.rabbitmq.send.Sender;
import com.gs.study.util.BaseController;
import com.gs.study.util.ResultJson;
/**
 * @author gs
 *
 */
@Controller
@RequestMapping(value="/rabbit")
public class RabbitController extends BaseController{
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private Sender sender;
	
	/**
	 * rabbit生产消息
	 * @return
	 */
    @RequestMapping(value="/send") 
    @ResponseBody
    public void send(){  
    	try {
			sender.send();
			ResultJson json=new ResultJson(true);
			printString(json.toString());
		} catch (Exception e) { 
			logger.error("异常");
		}
    } 
    
	/**
	 * rabbit生产消息
	 * @return
	 */
    @RequestMapping(value="/fanoutExchangeSend") 
    @ResponseBody
    public void fanoutExchangeSend(){  
    	sender.fanoutExchangeSend();
		ResultJson json=new ResultJson(true);
		logger.info("[发送时间] - [{}]", LocalDateTime.now());
		printString(json.toString());
    } 
    
	/**
	 * rabbit生产消息
	 * @return
	 */
    @RequestMapping(value="/topicExchangeSend") 
    @ResponseBody
    public void topicExchangeSend(){  
    	sender.topicExchangeSend();
		ResultJson json=new ResultJson(true);
		printString(json.toString());
    } 

}
